package util

import (
	"cm2/util"
	"fmt"
	"strings"
	"time"
)

// GenSerial 生成序列码
func GenSerial(sid string) string {
	now := time.Now()
	prefix := fmt.Sprintf("%4d%02d%02d%02d%02d%02d", now.Year(), now.Month(), now.Day(), now.Hour(), now.Minute(), now.Second())
	tail := fmt.Sprintf("%d%s", now.UnixNano(), util.Krand(4, 2))

	sids := strings.Split(sid, "_")
	sid = strings.Split(sids[len(sids)-1], "-")[0]

	return fmt.Sprintf("%s-%s-%s", prefix, sid, tail)
}
